﻿using carShop.Data.EntityFramework;
using carShop.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace carShop.Data.Repositories.Custom
{
    public class CarRepository: Repository<Car>
    {

       public CarRepository(CarShopDbContext dbContext)
            : base(dbContext)
        {
        }

        public IQueryable<Car> GetCarByIdWithIncludeProperties(int id,string properties)
        {
            if (properties == null)
            {
                throw new NotImplementedException();
            }
            var prop = properties.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            var query = (from c in dbContext.Car
                         where c.Id == id
                         select c);
            foreach (var p in prop)
            {
                query = query.Include("Image");
            }
                                                     
            return query;
        }

        public IEnumerable<Car> GetFeaturedCars()
        {

            throw new NotImplementedException();

        }
    }
}